package com.foton.designmodel.share.session;


import org.springframework.stereotype.Component;


/**
 * 通过【享元模式】，实现用户信息共享
 */

@Component
public class UserThreadLocal {

    private static final ThreadLocal<Session> userThreadLocal = new ThreadLocal<>();


    // 1：添加共享对象方法
    public void add(Session session) {
        userThreadLocal.set(session);
    }


    //2：获取共享对象方法
    public Session get(){
       return userThreadLocal.get();
    }


    //3：删除共享对象方法
    public void remove(){
        userThreadLocal.remove();
    }

}
